<?php

namespace App\Console\Commands;

use App\Models\Tool\Share;
use App\Models\Tool\TabBar;
use Illuminate\Console\Command;

class TestCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'test';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        //$this->handleShare();
        $this->handleTabbar();
        return 0;
    }


    public function handleTabbar()
    {
        $str = '[
        	{
        		"title": "磁力",
        		"icon":  "search",
        		"type":  "search",
        		"page":"/pages/index/index"
        	},
        	{
        		"title": "分享",
        		"icon":  "share-o",
        		"type":  "share",
        		"page":"/pages/share-link/index"
        	},
        	{
        		"title": "短剧",
        		"icon":  "video-o",
        		"type":  "video",
        		"page":"/pages/video/index"
        	},
        	{
        		"title": "我的",
        		"icon":  "user-o",
        		"type":  "mine",
        		"page":"/pages/mine/index"
        	}
        ]';
        $data = json_decode($str,true);
        TabBar::query()->insert($data);
    }

    public function handleShare()
    {
        $str = "appstorrent|| https://appstorrent.ru/
MacApp分享频道||  https://macapp.org.cn/
Digit77||  https://www.digit77.com
Mac玩儿法||  https://www.waerfa.com/
Xclient||  https://xclient.info/
马可菠萝||  https://www.macbl.com/
未来Mac下载||  https://mac.orsoon.com/
玩机手册||  https://www.rjsos.com/mac
麦氪派||  https://www.waitsun.com/topics/os
潘多拉盒子||  https://www.inpandora.com/
MCA|| www.mca.cool
MacDrop|| https://cmacked.com
Minopatch|| https://www.minorpatch.com/";
        $data = explode(PHP_EOL, $str);
        $pid = 7;
        //['title', 'pid', 'value', 'sort', 'type', 'remark', 'state', 'is_del', 'icon', 'is_free', 'points',];
        foreach ($data as $datum) {
            list($name, $url) = explode("||", $datum);
            Share::query()->create([
                'pid'     => $pid,
                'title'   => trim($name),
                'value'   => trim($url),
                'sort'    => 50,
                'type'    => 'copy',
                'remark'  => 'mac软件下载',
                'icon'    => '',
                'is_free' => 1,
                'points'  => 0,
            ]);
        }
    }
}
